import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { Singer, SingerDetail } from 'src/app/routes/entity';
import { BasicService } from './basic.service';

@Injectable()
export class SingerService extends BasicService {

  constructor(
    private http: HttpClient
  ) {
    super();
  }

  /** 获取入驻歌手列表 */
  getEnterSingers(): Observable<Singer[]> {
    const url = this.api('artist/list?cat=5001&limit=5');
    return this.http.get(url)
      .pipe(map((res: { artists: Singer[] }) => res.artists));
  }

  getSingerDetail(id: string): Observable<SingerDetail> {
    const url = this.api(`artists?id=${id}`);
    return this.http.get<SingerDetail>(url);
  }

  getSimiSinger(id: string): Observable<Singer[]> {
    const url = this.api(`simi/artist?id=${id}`);
    return this.http.get(url)
      .pipe(map((res: { artists: Singer[] }) => res.artists));
  }

}

